package com.jenkins.test.cron.task;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;

/**
 * @version V1.0.0
 * @ClassName: {@link XiaBanJob}
 * @Description: JobRunnable
 * @author: Lanzhou
 * @date: 2021/6/28 15:51
 * @Copyright:2020 All rights reserved.
 */
public class XiaBanJob implements JobRunnable {

    /**
     * 上午
     * 上下班下班时间
     */
    private static final String AM_GO = "08:00:00";
    /**
     * 上午
     * 上下班下班时间
     */
    private static final String AM_BO = "12:00:00";

    /**
     * 下午
     * 上下班下班时间
     */
    private static final String PM_GO = "13:30:00";
    /**
     * 下午
     * 上下班下班时间
     */
    private static final String PM_BO = "18:00:00";

    /**
     * 格式化
     */
    private static final DateTimeFormatter DTF = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");


    @Override
    public void run() {
        LocalDate nowDate = LocalDate.now();
        LocalDateTime nowDateTime = LocalDateTime.now();
        // 上下班时间
        LocalDateTime amGoValue = LocalDateTime.parse(nowDate.toString() + " " + AM_GO, DTF);
        LocalDateTime amBoValue = LocalDateTime.parse(nowDate.toString() + " " + AM_BO, DTF);
        LocalDateTime pmGoValue = LocalDateTime.parse(nowDate.toString() + " " + PM_GO, DTF);
        LocalDateTime pmBoValue = LocalDateTime.parse(nowDate.toString() + " " + PM_BO, DTF);
        long offsetAmGo = amGoValue.toInstant(ZoneOffset.of("+8")).toEpochMilli() - nowDateTime.toInstant(ZoneOffset.of("+8")).toEpochMilli();
        if (offsetAmGo >= 0) {
            System.out.println("还没上班呢");
            return;
        }
        long offsetPmBo = nowDateTime.toInstant(ZoneOffset.of("+8")).toEpochMilli() - pmBoValue.toInstant(ZoneOffset.of("+8")).toEpochMilli();
        if (offsetPmBo >= 0) {
            System.out.println("老早下班啦");
            return;
        }
        long offsetAmBo = nowDateTime.toInstant(ZoneOffset.of("+8")).toEpochMilli() - amBoValue.toInstant(ZoneOffset.of("+8")).toEpochMilli();
        long offsetPmGo = pmGoValue.toInstant(ZoneOffset.of("+8")).toEpochMilli() - nowDateTime.toInstant(ZoneOffset.of("+8")).toEpochMilli();
        if (offsetAmBo > 0 && offsetPmGo > 0) {
            System.out.println("现在是午休时间");
            return;
        }
        long amBoOf = nowDateTime.toInstant(ZoneOffset.of("+8")).toEpochMilli() - amGoValue.toInstant(ZoneOffset.of("+8")).toEpochMilli();
        long amPoOf = amBoValue.toInstant(ZoneOffset.of("+8")).toEpochMilli() - nowDateTime.toInstant(ZoneOffset.of("+8")).toEpochMilli();
        if (amBoOf > 0 && amPoOf > 0) {
            long seconds = amPoOf / 1000;
            long minute = amPoOf / 1000 / 60;
            long hour = amPoOf / 1000 / 60 / 60;
            System.out.println("现在距离下班时间还剩 " + hour + " 小时 " + minute + " 分 " + seconds + " 秒");
            return;
        }

        long pmBoOf = nowDateTime.toInstant(ZoneOffset.of("+8")).toEpochMilli() - pmGoValue.toInstant(ZoneOffset.of("+8")).toEpochMilli();
        long pmPoOf = pmBoValue.toInstant(ZoneOffset.of("+8")).toEpochMilli() - nowDateTime.toInstant(ZoneOffset.of("+8")).toEpochMilli();
        if (pmBoOf > 0 && pmPoOf > 0) {
            long seconds = pmPoOf / 1000;
            long minute = pmPoOf / 1000 / 60;
            long hour = pmPoOf / 1000 / 60 / 60;
            System.out.println("现在距离下班时间还剩 " + hour + " 小时 " + minute + " 分 " + seconds + " 秒");
            return;
        }

        System.out.println("你困入了时间裂缝啦 ~~");
    }

}
